#ifndef RECURSER_H
#define RECURSER_H

#include "FindFile.h"
#include "TestRunner.h"

class Recurser
{
	CPath m_start;
	TestRunner m_runner;

public:
	Recurser(const CPath& startingFolder, TDD::Discriminator& discriminator, TDD::Reporter& reporter)
		: m_start(startingFolder)
		, m_runner(discriminator, reporter)
	{}
	virtual ~Recurser() {}

	void Recurse() { Recurse(m_start); }

private:
	void Recurse(const CPath& csStartingFolder) 
	{
		CFindFile ff;

		// dlls first
		if (TRUE == ff.FindFile (csStartingFolder + _T("\\*.dll")))
		{
			do {
				if (TRUE != ff.IsDirectory())
				{
					m_runner.RunTests(CPath(ff.GetFilePath()));
				}
			} while (TRUE == ff.FindNextFile());
		}

		// now recurse into directories
		if (TRUE == ff.FindFile (csStartingFolder + _T("\\*.*")))
		{
			do {
				if (TRUE == ff.IsDirectory())
				{
					if (TRUE == ff.IsDots())
						continue;   // prevents infinite recursion

					Recurse(CPath(ff.GetFilePath()));
				}
			} while (TRUE == ff.FindNextFile());
		}
	}
};

#endif
